<?php
namespace app\admin\controller;
use clt\Tree;
use think\facade\Request;
use think\facade\Env;
use think\Db;
class Category extends Common
{
    public function index(){
        if(request()->isPost()){
            $key=input('post.key');
            $page =input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):config('pageSize');
            $list=db('orders')->alias('u')
                ->join(config('database.prefix').'users ul','u.user_id = ul.id','left')
                ->field('u.*,ul.username')
                ->where('u.order_number|u.total_fee|ul.username','like',"%".$key."%")
                ->where('u.status','neq',0)
                ->where('ul.status','eq',1)
                ->order('u.id desc')
                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                ->toArray();
            foreach($list['data'] as $k => $v){
                if($v['status'] == 1){
                    $list['data'][$k]['status'] = "未支付";
                }else{
                    $list['data'][$k]['status'] = "已完成";
                }
            }
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
        }
        return $this->fetch();
    }

    public function orderDel(){
        db::query('update hmp_orders set status = 0 where id ='.intval(input('id')));
        return $result = ['code'=>1,'msg'=>'删除成功!'];
    }

}